package StudyCode.summary.mycollection;

import java.util.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetsAMapFromIterable {
	static final Map<String, String> TEST_ENTRIES = null;

	static Map<String, String> getAltEntryMap(final String prefix,
	                                          final Iterable<String> subset) {
		assert prefix != null;
		return getEntryMap(Collections.singletonList(subset), prefix);
	}

	static Map<String, String> getEntryMap(final Iterable<String> subset) {
		return getEntryMap(Collections.singletonList(subset), null);
	}

	static Map<String, String> getEntryMap(final Iterable<String> subset1,
	                                       final Iterable<String> subset2) {
		final List<Iterable<String>> subsets = new ArrayList<Iterable<String>>(
				2);
		subsets.add(subset1);
		subsets.add(subset2);
		return getEntryMap(subsets, null);
	}

	static Map<String, String> getEntryMap(final Iterable<String> subset1,
	                                       final Iterable<String> subset2, final Iterable<String> subset3) {
		final List<Iterable<String>> subsets = new ArrayList<Iterable<String>>(
				3);
		subsets.add(subset1);
		subsets.add(subset2);
		subsets.add(subset3);
		return getEntryMap(subsets, null);
	}

	static Map<String, String> getEntryMap(final Iterable<String> subset1,
	                                       final Iterable<String> subset2, final Iterable<String> subset3,
	                                       final Iterable<String> subset4) {
		final List<Iterable<String>> subsets = new ArrayList<Iterable<String>>(
				4);
		subsets.add(subset1);
		subsets.add(subset2);
		subsets.add(subset3);
		subsets.add(subset4);
		return getEntryMap(subsets, null);
	}

	private static Map<String, String> getEntryMap(
			final List<Iterable<String>> subsets, final String prefix) {
		final StringBuilder sb = (prefix == null ? null
				: new StringBuilder(prefix));
		final Map<String, String> entryMap = new LinkedHashMap<String, String>();
		for (final Iterable<String> subset : subsets) {
			for (final String key : subset) {
				String value = TEST_ENTRIES.get(key);
				if (prefix != null) {
					sb.setLength(prefix.length());
					value = sb.append(value).toString();
				}
				entryMap.put(key, value);
			}
		}
		return entryMap;
	}
}
